package beer.coder.walawala.gui.handler.item;

import beer.coder.walawala.common.config.ItemConfigure;
import beer.coder.walawala.common.constant.ItemType;
import java.io.File;
import java.io.IOException;
import java.util.function.BiConsumer;
import javafx.application.Application;
import javafx.application.Platform;

/**
 * TODO
 *
 * @author amath0312
 * @version 1.0
 * @date 2019-10-27 20:18
 */
@ItemAction({ItemType.EXE, ItemType.LINK})
public class ExeItemHandler implements BiConsumer<Application, ItemConfigure> {

  @Override
  public void accept(Application application, ItemConfigure itemConfigure) {
    File file = new File(itemConfigure.getPath());

    ProcessBuilder processBuilder = new ProcessBuilder()
        .command("rundll32", "url.dll,FileProtocolHandler", itemConfigure.getPath())
        .directory(file.getParentFile());
    try {
      Process process = processBuilder.start();
      System.out.println(process.isAlive());
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
